<template>
  <div class="recommendList">
    <!-- 右上推荐人 -->
    <!-- <div v-for="(item, index) in selectList" :key="index" class="recommendItem">
        <div class="recommend">
          <img :src="item.img" alt="" class="header-img" />
          <div class="recommendInfo">
            <div class="name">{{ item.name }}</div>
            <div class="fans">{{ item.fans }}粉丝</div>
            <div>{{ item.text }}</div>
          </div>
        </div>
        <div class="follow">+关注</div>
      </div> -->
    <div class="recommendItem">
      <div class="recommend" v-for="(item, index) in show" :key="index"  @click="toDetail(item)">
        <div class="title">{{ item.title }}</div>
        <div class="time">
          <Icon type="ios-clock-outline" /> <span>{{ item.ready_stime }}-{{ item.ready_time }}</span>
        </div>
        <div :class="{'active':item.status ==1 }" class="bq"  v-if="item.status ==1">活动进行中</div>
        <div :class="{'active':item.status ==2 }" class="bq"  v-if="item.status ==2">活动报名中</div>
        <div :class="{'active':item.status ==1 }" class="bq" v-if="item.status ==0">活动未开始</div>
        <div :class="{'active':item.status ==1 }" class="bq"  v-if="item.status ==-1">活动已结束</div>
      </div>
    </div>
  </div>
</template>

<script>
import { follow } from "@/api/community";
import { time } from "@/config/time";
export default {
  props: {

  },
  data() {
    return {
      show: [],
      data: [],
      activeList: [],
    };
  },
  mounted() {
    this.getlist();
  },
  computed: {},
  methods: {

    //获取页面数据
    getlist() {
      let fow = {
        mid: JSON.parse(localStorage.userInfo).id,
        page: 1,
        pagesize: 5,
      };
      // console.log(fow);
      follow(fow).then((res) => {
        // console.log(res);
        if (res.code == 1) {
          if (res.code == 1) {
            var timer = time.now();
           const tempList = res.actdata.map((n) => {

              // 活动报名中2
              if (timer > n.ready_stime * 1000 && timer < n.ready_time * 1000) {
                n.status = 2;
              } else if (
                n.act_stime * 1000 < timer &&
                timer < n.act_time * 1000
              ) {
                // 活动进行中1
                n.status = 1;
              } else if (timer < n.act_stime * 1000  ) {
                // 活动未开始0
                n.status = 0;
              } else if (timer > n.act_time * 1000  ) {
                // 活动已结束 -1
                n.status = -1;
              }
              n.ready_stime = time.getallTime(n.ready_stime);
              // console.log( n.ready_stime,12312321);
              n.ready_time = time.getallTime(n.ready_time);
              return n
            });

            // 报名中数据
            const signUping = tempList.filter(it => {
              const ready_stime = new Date(it.ready_stime).valueOf()
              const ready_time = new Date(it.ready_time).valueOf()
              const current = new Date().valueOf()
              return  current > ready_stime  && current < ready_time
            })
            // 活动中数据
            const activing = tempList.filter(it => {
              const current = new Date().valueOf()
              return  current >  it.act_stime * 1000 && current < it.act_time * 1000
            })
             // 活动未开始
             const beforeActive = tempList.filter(it => {
              const current = new Date().valueOf()
              return  current < it.ready_stime * 1000
            })
            // 活动已结束
            const actived = tempList.filter(it => {
              const current = new Date().valueOf()
              return  current > it.act_time * 1000
            })
            this.show = [...signUping,...activing,...beforeActive,...actived].slice(0,3)
            this.data.map((v) => {
              v.creattime = time.getTime(v.creattime);
            });
            // console.log(this.show, "show");
          }
        }
      });
    },
     // 活动详情
     toDetail(item) {
      this.$router.push({
        path: `/active-detail?id=${item.id}`,
        // query: {
        //   id:item.id
        // }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.recommendList {
  .recommendItem {
    width: 90%;
    height: 200px;
    margin: 0 auto;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    //   border-bottom: 1px solid #ECECEC;
    background-color: rgba(255, 255, 255, 0.26);
    flex-wrap: wrap;
    .recommend {
      display: flex;
      width: 100%;
      height: 60px;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      position: relative;
      border-bottom: 1px solid #ececec;
      .title {
        width: 100%;
        font-size: 8px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #333333;
      }
      span {
        font-size: 7px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #878583;
      }
      .bq {
        position: absolute;
        right: 0;
        width: 65px;
        height: 17px;
        background: #dedede;
        border-radius: 3px 0px 0px 3px;
        font-size: 7px;
        font-weight: 400;
        color: #fff;
        text-align: center;
      }
      .bq.active {
        color: #35b572;
        background: #dcf8ee;
      }
    }
    //   .recommend {
    //     display: flex;
    //     // justify-content: space-between;
    //     .recommendInfo {
    //       .name{
    //           font-weight: bold;
    //       }
    //       .fans {
    //         background-color: #ccc;
    //         text-align: center;
    //         font-size: 8px;
    //         border-radius: 3px;
    //       }
    //     }
    //     .header-img {
    //       width: 40px;
    //       height: 40px;
    //       border-radius: 50%;
    //     }
    //   }
    //   .follow {
    //     width: 40px;
    //     height: 20px;
    //     line-height: 20px;
    //     text-align: center;
    //     color: #f00;
    //     margin-right: 20px;
    //     border-radius: 10px;
    //   }
  }
}
</style>
